import math 
from datetime import *

dmin = 0.1 # km
speed = 20 # km/h

def distance(p1, p2):
    dx = p1[0] - p2[0]
    dy = p1[1] - p2[1]
    return math.sqrt(dx*dx + dy*dy)

def normalizedDelta(p1, p2):
    d = distance(p1, p2)
    return (p2[0]-p1[0]) / d, (p2[1]-p1[1]) / d

def transportTime(p1, p2):
    d = distance(p1,p2)
    if d < 0.1:
        return 0
    return d / speed

def movePositionTowards(p1, p2, speed, dt):
    delta = normalizedDelta(p1, p2)
    dMovement = speed*dt.seconds/3600
    if distance(p1,p2) < dMovement:
        return p2
    return p1[0] + delta[0]*dMovement, p1[1] + delta[1]*dMovement

def calculateTransport(position, newPosition, speed, dt):
    tTime = transportTime(position, newPosition)
    if tTime > 0:
        position = movePositionTowards(position, newPosition, speed, dt)
        return position, "Transport"
    return None
